package com.josn.service.impl;

import com.josn.mapper.UserMapper;
import com.josn.pojo.User;
import com.josn.service.UserSercice;
import com.josn.utils.Md5Util;
import com.josn.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl implements UserSercice {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByUserName(String username) {
        return userMapper.findByUserName(username);
    }

    @Override
    public void add(String username,String password){
        String md5String= Md5Util.getMD5String(password);
        //添加
        userMapper.add(username,md5String);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void updateavatar(String avatarurl){
        Map<String,Object> map= ThreadLocalUtil.get();
        Integer id=(Integer) map.get("id");
        userMapper.updateavatar(avatarurl,id);
    }

    @Override
    public void updatepwd(String new_pwd){
        Map<String,Object> map= ThreadLocalUtil.get();
        Integer id=(Integer) map.get("id");
        String md5String = Md5Util.getMD5String(new_pwd);
        userMapper.updatepwd(md5String,id);
    }

}
